package com.dwb.service;

import com.dwb.entity.SYjfk;
import com.dwb.entity.SYjfkImages;
import com.dwb.mappers.SYjfkImagesMapper;
import com.dwb.mappers.SYjfkMapper;
import com.dwb.result.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author manke
 * @Date 2020/6/27 18:27
 * @Version 0.0.1
 */
@Service
public class SYjfkService {
    @Autowired
    private SYjfkMapper sYjfkMapper;
    @Autowired
    private SYjfkImagesMapper sYjfkImagesMapper;
    public PageInfo<SYjfk> getList(Map<String, String> parameters) {
        PageHelper.startPage(Integer.parseInt(parameters.get("pageNum") == null ? "" : "1"),
                Integer.parseInt(parameters.get("pageSize") == null ? "" : "10"));
        Example example =new Example(SYjfk.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("name","%"+(parameters.get("name") == null ? "" : parameters.get("name"))+"%");
        List<SYjfk> sYjfks = sYjfkMapper.selectByExample(example);
        return new PageInfo<>(sYjfks);

    }

    public Map<String, Object> getInfo(Map<String,Object> parameters) {
        HashMap<String , Object> map = new HashMap<>();
        SYjfk SYjfk = sYjfkMapper.selectByPrimaryKey(parameters.get("id"));
        map.put("feedback",SYjfk);
        Example example = new Example(SYjfkImages.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("yId",parameters.get("id"));
        List<SYjfkImages> sYjfkImages = sYjfkImagesMapper.selectByExample(example);
        map.put("feedbackImages",sYjfkImages);
        return map;


    }
}
